import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.*;
import java.util.*;
import java.util.List;

public class Manager extends JDialog {
    public Manager(JFrame frame){
        super(frame,"经理操作界面",true);
        setBounds(720,405,300,400);
        setLayout(new FlowLayout());

        Font font = new Font("SimSun",Font.BOLD, 15);
        //---------------------------------------------------------------------------------------
        JButton passwordCtrl = new JButton("密码管理");
        passwordCtrl.setPreferredSize(new Dimension(120, 60));
        passwordCtrl.setFont(font);
        //---------------------------------------------------------------------------------------
        JButton filmCtrl = new JButton("影片管理");
        filmCtrl.setPreferredSize(new Dimension(120, 60));
        filmCtrl.setFont(font);

        JButton arrangementCtrl = new JButton("排片管理");
        arrangementCtrl.setPreferredSize(new Dimension(120, 60));
        arrangementCtrl.setFont(font);

        JButton checkSaleData = new JButton("查看销售数据");
        checkSaleData.setPreferredSize(new Dimension(150, 60));
        checkSaleData.setFont(font);

        JButton exitLogIN = new JButton("退出登录");
        exitLogIN.setPreferredSize(new Dimension(120, 60));
        exitLogIN.setFont(font);
        //---------------------------------------------------------------------------------------

        add(passwordCtrl);
        add(filmCtrl);
        add(arrangementCtrl);
        add(checkSaleData);
        add(exitLogIN);

        passwordCtrl.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                passwordCtrlWindows passwordCtrlWindows = new passwordCtrlWindows(Manager.this);
                passwordCtrlWindows.setVisible(true);
            }
        });

        arrangementCtrl.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                arrangementCtrlWindows arrangementCtrlWindows = new arrangementCtrlWindows(Manager.this);
                arrangementCtrlWindows.setVisible(true);
            }
        });

        checkSaleData.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                checkSaleDataWindows checkSaleDataWindows = new checkSaleDataWindows(Manager.this);
                checkSaleDataWindows.setVisible(true);
            }
        });

        filmCtrl.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                FilmCtrlWindows filmCtrlWindows = new FilmCtrlWindows(Manager.this);
                filmCtrlWindows.setVisible(true);
            }
        });

        exitLogIN.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                User.nowUser = null;
                JOptionPane.showMessageDialog(null,"已经退出登录");
                dispose();
            }
        });
    }

    private static class checkSaleDataWindows extends JDialog{
        private checkSaleDataWindows(Manager frame) {
            super(frame, "经理操作界面", true);
            setBounds(720, 405, 400, 600);
            setLayout(new FlowLayout());
            LocalDateTime nowDateTime = LocalDateTime.now();

            JLabel label1 = new JLabel("当日销售额：");
            JLabel label2 = new JLabel("场次时间  销售票数  单价  退票数  退票金额");
            JLabel label3 = new JLabel("当周销售额：");
            JLabel label4 = new JLabel("当月销售额：");

            JButton exit = new JButton("退出");

            //场次时间  销售票数  单价  退票数  退票金额                总票价
            add(label1);
            add(label2);
            int totalPriceDay = 0;
            LocalDate nowDate = nowDateTime.toLocalDate();
            for(Map.Entry<List<String>, List<String>> entry : Cinema.getCinemaMap().entrySet()){
                List<String> key = entry.getKey();
                List<String> values = Cinema.getCinemaMap().get(key);
                LocalDateTime dateTime = LocalDateTime.parse(key.get(0));
                if(dateTime.toLocalDate().equals(nowDate)){
                    JLabel label = new JLabel(key.get(0)+" "+Cinema.getTicketSales(key.get(0))+" "+Cinema.getTicketPrice(key.get(0))+" "+Cinema.getTicketRefund(key.get(0))+" "+Cinema.getTicketRefund(key.get(0))*Cinema.getTicketPrice(key.get(0)));
                    add(label);
                    totalPriceDay += Cinema.getTicketPrice(key.get(0))*Cinema.getCol(key.get(0))*Cinema.getRow(key.get(0));
                }
            }
                    JLabel dayTotalPrice = new JLabel("总票价："+totalPriceDay);
                    add(dayTotalPrice);


            int totalPriceWeek = 0;
            int totalSalesWeek = 0;
            int totalTicketRefundWeek = 0;
            int totalPriceRefundWeek = 0;
            int totalTicketPriceWeek = 0;

            for(Map.Entry<List<String>, List<String>> entry : Cinema.getCinemaMap().entrySet()){
                List<String> key = entry.getKey();
                List<String> values = Cinema.getCinemaMap().get(key);
                LocalDateTime dateTime = LocalDateTime.parse(key.get(0));
                if(Period.between(nowDate, LocalDate.from(dateTime)).getDays() >= 0 && Period.between(nowDate, LocalDate.from(dateTime)). getDays() <= 7){
                    totalPriceWeek += Cinema.getTicketPrice(key.get(0))*Cinema.getTicketSales(key.get(0));
                    totalTicketPriceWeek += Cinema.getTicketPrice(key.get(0))*Cinema.getCol(key.get(0))*Cinema.getRow(key.get(0));
                    totalTicketRefundWeek += Cinema.getTicketRefund(key.get(0));
                    totalPriceRefundWeek += Cinema.getTicketRefund(key.get(0))*Cinema.getTicketPrice(key.get(0));
                    totalSalesWeek += Cinema.getTicketSales(key.get(0));
                }
            }

            JLabel weekTotalPrice = new JLabel("总票价："+totalTicketPriceWeek);
            JLabel weekTotalSales = new JLabel("总销售额："+totalPriceWeek);
            JLabel weekTotalTicketRefund = new JLabel("总退票数："+totalTicketRefundWeek);
            JLabel weekTotalPriceRefund = new JLabel("总退票金额："+ totalPriceRefundWeek);
            JLabel weekTotalTicketSales = new JLabel("总售票数："+totalSalesWeek);
            add(label3);
            add(weekTotalPrice);
            add(weekTotalSales);
            add(weekTotalTicketRefund);
            add(weekTotalPriceRefund);
            add(weekTotalTicketSales);


            int totalPriceMonth = 0;
            int totalSalesMonth = 0;
            int totalTicketRefundMonth = 0;
            int totalPriceRefundMonth = 0;
            int totalTicketPriceMonth = 0;

            for(Map.Entry<List<String>, List<String>> entry : Cinema.getCinemaMap().entrySet()){
                List<String> key = entry.getKey();
                List<String> values = Cinema.getCinemaMap().get(key);
                LocalDateTime dateTime = LocalDateTime.parse(key.get(0));
                if(Period.between(nowDate, LocalDate.from(dateTime)).getMonths() >= 0 && Period.between(nowDate, LocalDate.from(dateTime)). getMonths() <= 1){
                    totalPriceMonth += Cinema.getTicketPrice(key.get(0))*Cinema.getTicketSales(key.get(0));
                    totalTicketPriceMonth += Cinema.getTicketPrice(key.get(0))*Cinema.getCol(key.get(0))*Cinema.getRow(key.get(0));
                    totalTicketRefundMonth += Cinema.getTicketRefund(key.get(0));
                    totalPriceRefundMonth += Cinema.getTicketRefund(key.get(0))*Cinema.getTicketPrice(key.get(0));
                    totalSalesMonth += Cinema.getTicketSales(key.get(0));
                }
            }

            JLabel monthTotalPrice = new JLabel("总票价："+totalPriceMonth);
            JLabel monthTotalSales = new JLabel("总销售额："+totalTicketPriceMonth);
            JLabel monthTotalTicketRefund = new JLabel("总退票数："+totalTicketRefundMonth);
            JLabel monthTotalPriceRefund = new JLabel("总退票金额："+totalPriceRefundMonth);
            JLabel monthTotalTicketSales = new JLabel("总售票数："+totalSalesMonth);
            add(label4);
            add(monthTotalPrice);
            add(monthTotalSales);
            add(monthTotalTicketRefund);
            add(monthTotalPriceRefund);
            add(monthTotalTicketSales);

            exit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null,"已经退出");
                    dispose();
                }

            });

        }
    }

    private static class arrangementCtrlWindows extends JDialog{
        private arrangementCtrlWindows(Manager frame) {
            super(frame, "经理操作界面", true);
            setBounds(720, 405, 400, 600);
            setLayout(new FlowLayout());

            LocalDateTime nowDateTime = LocalDateTime.now();

            JLabel label1 = new JLabel("请输入要排片的影片名");
            JLabel label2 = new JLabel("请输入排片时间(可以安排一周 格式：yyyy-MM-ddTHH:mm)");
            JLabel label3 = new JLabel("请输入播放影片的影厅");
            JLabel label4 = new JLabel("请输入票价");
            JLabel label5 = new JLabel("请输入要修改场次的时间(格式：yyyy-MM-ddTHH:mm)");
            JLabel label6 = new JLabel("请输入要修改场次的新时间");
            JLabel label7 = new JLabel("请输入要修改场次的影厅");
            JLabel label8 = new JLabel("请输入要修改场次的电影名");
            JLabel label9 = new JLabel("请输入要修改的票价");
            JLabel label10 = new JLabel("请输入要删除场次的时间(格式：yyyy-MM-ddTHH:mm)");




            JTextField filmName = new JTextField(10);
            JTextField time = new JTextField(10);
            JTextField hall = new JTextField(10);
            JTextField price = new JTextField(10);
            JTextField time1 = new JTextField(10);
            JTextField time2 = new JTextField(10);
            JTextField hall1 = new JTextField(10);
            JTextField filmName1 = new JTextField(10);
            JTextField price1 = new JTextField(10);
            JTextField time3 = new JTextField(10);



            JButton confirm = new JButton("确认");
            JButton confirm1 = new JButton("确认");
            JButton confirm2 = new JButton("确认");
            JButton list = new JButton("查看排片表");
            JButton autoArrangement = new JButton("自动排片");
            JButton exit = new JButton("退出");


            add(label1);
            add(filmName);
            add(label2);
            add(time);
            add(label3);
            add(hall);
            add(label4);
            add(price);
            add(confirm);
            add(label5);
            add(time1);
            add(label6);
            add(time2);
            add(label7);
            add(hall1);
            add(label8);
            add(filmName1);
            add(label9);
            add(price1);
            add(confirm1);
            add(label10);
            add(time3);
            add(confirm2);
            add(list);
            add(autoArrangement);
            add(exit);

            autoArrangement.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    LocalTime fixedTime = LocalTime.of(8, 0);
                    LocalDateTime fixedDateTime = nowDateTime.with(fixedTime);
                    float price = 50;
                    Random random = new Random();

                    List<String> filmNameRandom = new ArrayList<>();

                    int i = 0;
                    for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                        String key = entry.getKey();
                        if(Film.getFilmList().get(key).get(5).equals("已上映")) {
                            List<String> values = Film.getFilmList().get(key);
                            filmNameRandom.add(key);
                            i++;
                        }
                    }


                    for(int j = 1;j <= 7;j++) {
                        for (int k = 0; k < 4; k++) {
                            for(HashMap.Entry<String, List<Integer>> entry : Cinema.getCinemaRoom().entrySet()){
                                int filmRandomNumber = random.nextInt(filmNameRandom.size());
                                String key = entry.getKey();

                                if(k==3){
                                    boolean flag = false;
                                    price *= 1.25F;
                                    for(int p = 0; p < filmRandomNumber; p++){
                                        if (Film.getFilmScore(filmNameRandom.get(filmRandomNumber)) >= 9.0) {
                                            flag = true;
                                            Cinema.setCinema(fixedDateTime.plusDays(j).plusHours(k * 3).toString(), key, filmNameRandom.get(p));
                                            Cinema.setCinemaPrice(fixedDateTime.plusDays(j).plusHours(k*3).toString(), price*1.25f);
                                            break;
                                        }
                                    }
                                    if(!flag){
                                        Cinema.setCinema(fixedDateTime.plusDays(j).plusHours(k * 3).toString(), key, filmNameRandom.get(filmRandomNumber));
                                        Cinema.setCinemaPrice(fixedDateTime.plusDays(j).plusHours(k*3).toString(), price);
                                    }
                                }else{
                                    Cinema.setCinema(fixedDateTime.plusDays(j).plusHours(k * 3).toString(), key, filmNameRandom.get(filmRandomNumber));
                                    Cinema.setCinemaPrice(fixedDateTime.plusDays(j).plusHours(k*3).toString(), price);
                                }
                                price = 50;

                                        Cinema.setCinemaSeat(fixedDateTime.plusDays(j).plusHours(k * 3).toString(),key,false,Cinema.getRow(key), Cinema.getCol(key));
                            }

                        }
                    }
                    JOptionPane.showMessageDialog(null,"自动排片成功");
                }
            });

            list.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                    JDialog ArrangementList = new JDialog(frame,"排片表",true);
                    ArrangementList.setBounds(720,405,400,1080);
                    Container c = ArrangementList.getContentPane();
                    c.setLayout(new FlowLayout());
                    for(Map.Entry<List<String>, List<String>> entry : Cinema.getCinemaMap().entrySet()){
                        List<String> key = entry.getKey();
                        List<String> values = Cinema.getCinemaMap().get(key);
                        String str = "|#|"+key.get(0) + "  |" + key.get(1) + "  |" + values.getFirst() + "  |" + Cinema.getTicketPrice(key.get(0))+"|#|";
                        JLabel film = new JLabel(str);
                        c.add(film);
                    }

                    ArrangementList.setVisible(true);
                }
            });

            confirm2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean flag = false;
                    for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                        String key = entry.getKey();
                        if(time1.getText().equals(key)){
                            flag = true;
                            if(Cinema.getTicketSales(time1.getText()) > 0){
                                JOptionPane.showMessageDialog(null,"该场次已经售出票，无法修改");
                            }else {
                                Cinema.removeCinema(time1.getText());
                                JOptionPane.showMessageDialog(null, "已经删除排片");
                                Log.setLogger(User.nowUser + "删除了" + time1.getText() + "的排片,删除的片名：" + Cinema.getCinemaMap().get(key).get(1));
                            }
                        }
                    }

                    if(!flag){
                        JOptionPane.showMessageDialog(null, "删除排片失败，请检查输入是否正确");
                    }
                }
            });

            confirm1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean flag = false;
                    for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                        String key = entry.getKey();
                        if(time1.getText().equals(key)){
                            flag = true;
                            if(Cinema.getTicketSales(time1.getText()) > 0){
                                JOptionPane.showMessageDialog(null,"该场次已经售出票，无法修改");
                            }else{
                                Cinema.changeCinemaTime(time1.getText(), time2.getText(), hall1.getText(), filmName1.getText());
                                Cinema.setCinemaPrice(time1.getText(), Integer.parseInt(price1.getText()));
                                JOptionPane.showMessageDialog(null, "已经修改排片");
                                Log.setLogger(User.nowUser+ "修改了" + time1.getText() + "的排片,修改后的片名：" + filmName1.getText() + "，修改后的时间：" + time2.getText() + "，修改后的影厅：" + hall1.getText() + "，修改后的票价：" + price1.getText());
                            }

                        }
                    }

                    if(!flag){
                        JOptionPane.showMessageDialog(null, "修改排片失败，请检查输入是否正确");
                    }
                }
            });


            confirm.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean flag = false;
                    LocalDateTime timeDateTime = LocalDateTime.parse(time.getText());
                    Duration duration = Duration.between(nowDateTime,timeDateTime);

                    for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                        String key = entry.getKey();
                        if(duration.toDays() <= 7 && duration.toDays() >= 0 && filmName.getText().equals(key)){
                            flag = true;
                            Cinema.setCinema(time.getText(), hall.getText(), filmName.getText());
                            Cinema.setCinemaPrice(time.getText(), Integer.parseInt(price.getText()));
                            JOptionPane.showMessageDialog(null, "已经新增排片");
                        }
                    }
                    Cinema.setCinemaSeat(time.getText(),hall.getText(),false,Cinema.getRow(hall.getText()), Cinema.getCol(hall.getText()));


                    if(!flag){
                        JOptionPane.showMessageDialog(null, "排片失败，请检查输入是否正确");
                    }
                }
            });




            exit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null,"已经退出");
                    dispose();
                }

            });
        }
    }


    private static class passwordCtrlWindows extends JDialog{
        private passwordCtrlWindows(Manager frame) {
            super(frame, "经理操作界面", true);
            setBounds(720, 405, 400, 300);
            setLayout(new FlowLayout());

            JButton exit = new JButton("退出");
            JLabel label1 = new JLabel("请输入新经理密码");
            JLabel label2 = new JLabel("请输入要重置密码的前台账号（重置后密码：123456）");
            JTextField username = new JTextField(10);
            JPasswordField newPwd = new JPasswordField(10);
            JButton confirm1 = new JButton("确认");
            JButton confirm2 = new JButton("确认");

            add(label1);
            add(newPwd);
            add(confirm1);
            add(label2);
            add(username);
            add(confirm2);
            add(exit);

            confirm1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String pwd = new String(newPwd.getPassword());
                    User.setUserMap(User.nowUser,pwd,"经理",User.getUserMap().get(User.nowUser).get(2),User.getUserMap().get(User.nowUser).get(3));
                    Log.setLogger("操作类型：经理修改自己密码，操作人："+User.nowUser);
                    JOptionPane.showMessageDialog(null,"已经修改");
                    dispose();
                }
            });

            confirm2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean flag = false;
                    for(Map.Entry<String, List<String>> entry : User.getUserMap().entrySet()){
                        String key = entry.getKey();
                        List<String> values = User.getUserMap().get(key);
                        if(  values.get(1).equals("前台") && key.equals(username.getText()) ){
                            flag = true;
                            User.setUserMap(key,"123456",values.get(1),values.get(2),values.get(3));
                            Log.setLogger("操作类型：经理重置"+values.get(1)+key+"密码"+"，操作人："+User.nowUser);
                            JOptionPane.showMessageDialog(null,"已经重置");
                            dispose();
                            break;
                        }
                    }
                    if(!flag) {
                        JOptionPane.showMessageDialog(null, "重置失败，没有找到该用户或您没有重置该用户权限");
                        dispose();
                    }
                }
            });

            exit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null,"已经退出");
                    dispose();
                }
            });
        }
    }


    private static class FilmCtrlWindows extends JDialog{
        private FilmCtrlWindows(Manager frame) {
            super(frame, "经理操作界面", true);
            setBounds(720, 405, 1920, 1080);
            setLayout(new FlowLayout());

            JLabel label1 = new JLabel("电影名称    导演     主演      简介                                                                                                                                                                                                                                                时长      评分");
            JLabel label2 = new JLabel("请输入要添加的电影名称");
            JLabel label3 = new JLabel("导演:");
            JLabel label4 = new JLabel("主演:");
            JLabel label5 = new JLabel("简介:");
            JLabel label6 = new JLabel("时长:");
            JLabel label7 = new JLabel("评分:");
            JLabel label8 = new JLabel("请选择要修改的类型并输入要修改的电影名称");
            JLabel label9 = new JLabel("请输入修改后的内容");
            JLabel label10 = new JLabel("请输入要删除的电影名称");
            JLabel label11 = new JLabel("请输入要查询的电影（单独查询）");
            JLabel label12 = new JLabel("请输入要查询的电影（组合查询）");


            JComboBox<String> box = new JComboBox<>();
            JTextField name = new JTextField(10);
            JTextField nowName = new JTextField(10);
            JTextField revise = new JTextField(10);
            JTextField director = new JTextField(10);
            JTextField actor = new JTextField(10);
            JTextField intro = new JTextField(100);
            JTextField time = new JTextField(10);
            JTextField score = new JTextField(10);
            JTextField deleteFilm = new JTextField(10);
            JTextField checkFilm1 = new JTextField(10);
            JTextField checkFilm2 = new JTextField(10);
            JTextField checkFilm3 = new JTextField(10);
            JTextField checkFilm4 = new JTextField(10);

            JButton confirm1 = new JButton("确认添加");
            JButton confirm2 = new JButton("确认修改");
            JButton confirm3 = new JButton("确认删除");
            JButton confirm4 = new JButton("确认查询");
            JButton exit = new JButton("退出");

            box.addItem("电影名称");
            box.addItem("导演");
            box.addItem("主演");
            box.addItem("简介");
            box.addItem("时长");
            box.addItem("评分");


            add(label1);
            for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                String key = entry.getKey();
                List<String> values = Film.getFilmList().get(key);
                String str = key + "  |" + values.get(0) + "  |" + values.get(1) + "  |" + values.get(2) + "  |" + values.get(3) + "  |" + values.get(4);
                JLabel film = new JLabel(str);
                add(film);
            }
            add(label2);
            add(name);
            add(label3);
            add(director);
            add(label4);
            add(actor);
            add(label5);
            add(intro);
            add(label6);
            add(time);
            add(label7);
            add(score);
            add(confirm1);
            add(label8);
            add(nowName);
            add(box);
            add(label9);
            add(revise);
            add(confirm2);
            add(label10);
            add(deleteFilm);
            add(confirm3);
            add(label11);
            add(checkFilm1);
            add(label12);
            add(checkFilm2);
            add(checkFilm3);
            add(checkFilm4);
            add(confirm4);
            add(exit);

            confirm4.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                    boolean flag = false;
                    JDialog solution = new JDialog(frame,"查询结果",true);
                    solution.setBounds(720,405,720,280);
                    Container c = solution.getContentPane();
                    c.setLayout(new FlowLayout());
                    JLabel label = new JLabel("查询结果：");
                    c.add(label);


                    for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                        String key = entry.getKey();
                        ArrayList<String> values = (ArrayList<String>) Film.getFilmList().get(key);
                        if(key.equals(checkFilm1.getText()) || values.get(0).equals(checkFilm1.getText()) || values.get(1).equals(checkFilm1.getText())){
                            flag = true;
                            String strFilm = key + "  |" + values.get(0) + "  |" + values.get(1) + "  |" + values.get(2) + "  |" + values.get(3) + "  |" + values.get(4);
                            JLabel film = new JLabel(strFilm);
                            c.add(film);
                        }
                        if(key.equals(checkFilm2.getText()) && values.get(0).equals(checkFilm3.getText()) && values.get(1).equals(checkFilm4.getText())){
                            flag = true;
                            String strFilm = key + "  |" + values.get(0) + "  |" + values.get(1) + "  |" + values.get(2) + "  |" + values.get(3) + "  |" + values.get(4);
                            JLabel film = new JLabel(strFilm);
                            c.add(film);
                        }
                    }
                    if(!flag){
                        JLabel film = new JLabel("未查询到");
                        c.add(film);
                    }
                    solution.setVisible(true);
                }
            });





            confirm1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Film.addFilm(name.getText(),director.getText(),actor.getText(),intro.getText(),time.getText(),score.getText(),"未上映");
                    JOptionPane.showMessageDialog(null,"已经添加");
                }
            });

            confirm2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean flag = false;
                    for(Map.Entry<String, List<String>> entry : Film.getFilmList().entrySet()){
                        String key = entry.getKey();
                        ArrayList<String> values = (ArrayList<String>) Film.getFilmList().get(key);
                        if(key.equals(nowName.getText())&&box.getSelectedItem().equals("电影名称")){
                            flag = true;
                            Film.updateFilmName(key,revise.getText(),values,Film.getFilmSale().get(key));
                            JOptionPane.showMessageDialog(null,"已经修改");
                            break;
                        } else if (key.equals(nowName.getText())&&box.getSelectedItem().equals("导演")) {
                            flag = true;
                            Film.updateFilmEditorName(key,revise.getText());
                            JOptionPane.showMessageDialog(null,"已经修改");
                            break;
                        }else if (key.equals(nowName.getText())&&box.getSelectedItem().equals("主演")){
                            flag = true;
                            Film.updateFilmStarring(key,revise.getText());
                            JOptionPane.showMessageDialog(null,"已经修改");
                            break;
                        }else if (key.equals(nowName.getText())&&box.getSelectedItem().equals("简介")){
                            flag = true;
                            Film.updateFilmIntroduction(key,revise.getText());
                            JOptionPane.showMessageDialog(null,"已经修改");
                            break;
                        }else if (key.equals(nowName.getText())&&box.getSelectedItem().equals("时长")){
                            flag = true;
                            Film.updateFilmTime(key,revise.getText());
                            JOptionPane.showMessageDialog(null,"已经修改");
                            break;
                        }else if (key.equals(nowName.getText())&&box.getSelectedItem().equals("评分")){
                            flag = true;
                            Film.updateFilmScore(key,revise.getText());
                            JOptionPane.showMessageDialog(null,"已经修改");
                            break;
                        }
                    }
                    if(!flag){
                        JOptionPane.showMessageDialog(null,"不存在该电影");
                    }
                }
            });

            confirm3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean flag = false;
                    JDialog confirmF = new JDialog(frame,"确认删除",true);
                    confirmF.setBounds(720,405,150,100);
                    Container c = confirmF.getContentPane();
                    c.setLayout(new FlowLayout());
                    JLabel label = new JLabel("确认删除该电影？");
                    c.add(label);
                    JButton confirmY = new JButton("确认");
                    JButton confirmN = new JButton("取消");
                    c.add(confirmY);
                    c.add(confirmN);
                    for(Map.Entry<String, List<String>> entry : User.getUserMap().entrySet()) {
                        String key = entry.getKey();
                        List<String> values = User.getUserMap().get(key);
                        if(deleteFilm.getText().equals((key))) {
                            flag = true;
                            confirmY.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    if (Film.getFilmList().get(key).get(3).equals("已上映")) {
                                        JOptionPane.showMessageDialog(null, "该电影正在上映，无法删除");
                                        confirmF.dispose();

                                    }else {
                                        Film.deleteFilm(deleteFilm.getText());
                                        JOptionPane.showMessageDialog(null, "已经删除");
                                        confirmF.dispose();
                                    }
                                }
                            });
                            break;
                        }
                        confirmN.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                confirmF.dispose();
                            }
                        });
                    }
                    if(!flag){
                        JOptionPane.showMessageDialog(null,"不存在该电影");
                        confirmF.dispose();
                    }
                    confirmF.setVisible(true);
                }
            });

            exit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null,"已经退出");
                    dispose();
                }
            });

        }
    }
}
